/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author eltorre
 */
@Entity
@Table(name = "Obras")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Obra.findAll", query = "SELECT o FROM Obra o"),
    @NamedQuery(name = "Obra.findById", query = "SELECT o FROM Obra o WHERE o.id = :id"),
    @NamedQuery(name = "Obra.findByNombre", query = "SELECT o FROM Obra o WHERE o.nombre = :nombre"),
    @NamedQuery(name = "Obra.findByAutor", query = "SELECT o FROM Obra o WHERE o.autor = :autor"),
    @NamedQuery(name = "Obra.findByAnyo", query = "SELECT o FROM Obra o WHERE o.anyo = :anyo"),
    @NamedQuery(name = "Obra.findByEstadoConservacion", query = "SELECT o FROM Obra o WHERE o.estadoConservacion = :estadoConservacion")})
public class Obra implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "nombre")
    private String nombre;
    @Basic(optional = false)
    @Column(name = "autor")
    private String autor;
    @Basic(optional = false)
    @Column(name = "anyo")
    private int anyo;
    @Basic(optional = false)
    @Column(name = "estadoConservacion")
    private String estadoConservacion;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "obra1")
    private List<ClientePropietarioObra> clientePropietarioObraList;
    @JoinColumn(name = "usuarioAlta", referencedColumnName = "id")
    @ManyToOne
    private Usuarios usuarioAlta;

    public Obra() {
    }

    public Obra(Integer id) {
        this.id = id;
    }

    public Obra(Integer id, String nombre, String autor, int anyo, String estadoConservacion) {
        this.id = id;
        this.nombre = nombre;
        this.autor = autor;
        this.anyo = anyo;
        this.estadoConservacion = estadoConservacion;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        String oldNombre = this.nombre;
        this.nombre = nombre;
        changeSupport.firePropertyChange("nombre", oldNombre, nombre);
    }

    public String getAutor() {
        return autor;
    }

    public void setAutor(String autor) {
        String oldAutor = this.autor;
        this.autor = autor;
        changeSupport.firePropertyChange("autor", oldAutor, autor);
    }

    public int getAnyo() {
        return anyo;
    }

    public void setAnyo(int anyo) {
        int oldAnyo = this.anyo;
        this.anyo = anyo;
        changeSupport.firePropertyChange("anyo", oldAnyo, anyo);
    }

    public String getEstadoConservacion() {
        return estadoConservacion;
    }

    public void setEstadoConservacion(String estadoConservacion) {
        String oldEstadoConservacion = this.estadoConservacion;
        this.estadoConservacion = estadoConservacion;
        changeSupport.firePropertyChange("estadoConservacion", oldEstadoConservacion, estadoConservacion);
    }

    @XmlTransient
    public List<ClientePropietarioObra> getClientePropietarioObraList() {
        return clientePropietarioObraList;
    }

    public void setClientePropietarioObraList(List<ClientePropietarioObra> clientePropietarioObraList) {
        this.clientePropietarioObraList = clientePropietarioObraList;
    }

    public Usuarios getUsuarioAlta() {
        return usuarioAlta;
    }

    public void setUsuarioAlta(Usuarios usuarioAlta) {
        Usuarios oldUsuarioAlta = this.usuarioAlta;
        this.usuarioAlta = usuarioAlta;
        changeSupport.firePropertyChange("usuarioAlta", oldUsuarioAlta, usuarioAlta);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Obra)) {
            return false;
        }
        Obra other = (Obra) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Obra[ id=" + id + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
